package com.cz.datafetcher.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cz.datafetcher.entity.ProductionDevices;
import com.cz.datafetcher.entity.search.ProductionDevicesSearch;
import com.cz.datafetcher.service.ProductionDevicesService;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/productionDevices")
@Api(tags = "生产设备")
public class ProductionDevicesController
        extends SingleTabControllerBase<ProductionDevices, Integer, ProductionDevicesService, ProductionDevicesSearch> {

    @Override
    protected QueryWrapper<ProductionDevices> buildQueryWrapper(ProductionDevicesSearch s) {
        QueryWrapper<ProductionDevices> qw = new QueryWrapper<>();

        if(s.getId()!=null){
            qw.lambda().eq(ProductionDevices::getId,s.getId());
            return qw;
        }
        qw.lambda()
                .in(s.getIds()!=null && s.getIds().length>0,ProductionDevices::getId,s.getIds())
                .like(StringUtils.isNotBlank(s.getName()), ProductionDevices::getName,s.getName())
                .like(StringUtils.isNotBlank(s.getSn()),ProductionDevices::getSn,s.getSn());

        return qw;
    }

    @Override
    protected Integer getKeyFromObj(ProductionDevices productionDevices) {
        return productionDevices.getId();
    }
}
